<!-- 电子巡塘管理 -->
<template>
  <BaseMainSlot :show-btn-box="false">
    <template v-slot:search-box>
      <el-collapse v-model="activeName" accordion>
        <el-collapse-item name="1">
          <template slot="title">
            <div class="select-btns search-btns" @click.stop="changeSelect()">
              <i class="el-icon-circle-check"></i>
              <p v-if="activeName === '1'">收起筛选</p>
              <p v-if="activeName === ''">展开筛选</p>
            </div>
          </template>
          <div class="search-btn search-btns" @click.stop="search()">
            <i class="el-icon-circle-check"></i>
            <p>查询</p>
          </div>
          <div class="select-box-content">
            <div class="select-box-content-name">巡查人员名称</div>
            <el-select filterable clearable v-model="staffName" clearable filterable>
              <el-option v-for="item in staffList" :key="item.staffId" :label="item.staffName" :value="item.staffName" />
            </el-select>
          </div>

          <div class="select-box-content">
            <div class="select-box-content-name">开始时间</div>
            <!-- <StartTimeEndTimeSelectionBox @startVal="startVal" @endVal="endVal" /> -->
            <el-date-picker v-model="startTime" type="date" placeholder="选择日期" value-format="yyyy-MM-dd" clearable />
          </div>

          <div class="select-box-content">
            <div class="select-box-content-name">结束时间</div>
            <!-- <StartTimeEndTimeSelectionBox @startVal="startVal" @endVal="endVal" /> -->
            <el-date-picker v-model="endTime" type="date" placeholder="选择日期" value-format="yyyy-MM-dd" clearable />
          </div>
        </el-collapse-item>
      </el-collapse>
       <ActionBar :export-active="true" :hasExport="true" :hasAdd="false" :hasDel="false" :page-no="162" @add="add"
        @del="del" @exportFile="exportFile" />
    </template>

    <template v-slot:table-box>
      <el-table ref="tableData" v-loading="loading" :data="tableData" stripe border height="88%"
        @selection-change="handleSelectionChange">
        <el-table-column type="index" label="序号" width="50" />
        <el-table-column prop="staffName" label="巡检人员名称" />
        <el-table-column prop="inspectionTime" label="巡检时间" />

        <el-table-column label="是否异常">
          <template slot-scope="scope" v-if="scope.row.whetherNormal">
            <span>{{ scope.row.whetherNormal == 'true' ? '正常' : '异常' }}</span>
          </template>
        </el-table-column>
        <!-- <el-table-column prop="remark" label="巡检说明" /> -->
        <el-table-column label="巡检说明">
          <template slot-scope="scope" v-if="scope.row.electronicPatrolId">
            {{scope.row.remark?scope.row.remark:'--'}}
          </template>
        </el-table-column>
        <el-table-column label="查看图片">
          <template slot-scope="scope" v-if="scope.row.electronicPatrolId">
            <el-button type="text" @click="showResult(scope.row.pictureIdList)">查看图片</el-button>
          </template>
        </el-table-column>
      </el-table>

      <el-dialog :title="(titleText || '') + '图片'" :visible="showPictureDialog" @close="closePictureDialog" width="50%">
        <div v-if="pictureIdList.length > 0" style="height:500px;overflow: auto;">
          <img :src="item" v-for="(item, index) in imageDataList" width="100%" style=" margin: 0 10px;" alt=""
            :key="index + 'imageData'" />
        </div>
        <div v-else class="empty-content"><span>暂无图片</span></div>
      </el-dialog>
      <Pagination :page-size="pageSize" :current-page="currentPage" :total-size="totalSize"
        @changePageSize="changePageSize" @changeCurrentPage="changeCurrentPage" />
      <ExportBtn :btnName="'电子巡塘记录'" ref="ExportBtn" :apiName="'electronicPatrol'" :searchObj="searchObj"></ExportBtn>
    </template>
  </BaseMainSlot>
</template>

<script>
import ActionBar from "@/components/ActionBar";   // 导出样式
import ExportBtn from "@/components/ExportBtn";   // 导出功能
import Pagination from "@/components/Pagination";
import BaseMainSlot from "@/components/BaseMainSlot/newBaseMainSlot.vue";
import SearchBox from "@/components/SearchBox";
import { blobToBase64 } from "@/utils/convert";
import StartTimeEndTimeSelectionBox from "@/components/StartTimeEndTimeSelectionBox";
import staffApi from "@/api/basic-info-manage/staff/index";
import patrolInfoApi from "@/api/pond-patrol-management/patrol-line-manage";
import { mymixin } from "@/utils/mixins";
import HistoryPatrolPondRecordApi from "@/api/pond-patrol-management/history-patrol-pond-record/index";
import PatrolPointManageApi from "@/api/pond-patrol-management/patrol-point-manage/index";
import inspectionElectronicPatrolApi from "@/api/inspection-management/inspection-electronicPatrol"


export default {
  name: "ElectronicPatrolRecord",
  components: {
    Pagination,
    BaseMainSlot,
    StartTimeEndTimeSelectionBox,
    SearchBox,
    ActionBar,ExportBtn
  },
  mixins: [mymixin],
  data () {
    return {
      searchObj:{},
      // 巡塘基地名称
      PatrolBaseList: [],
      // 选中的数据项数组 ID组成
      taskIdList: [],
      // 展示图片
      isShowimage: false,
      // 鱼塘批次详细信息列表
      resultDatatwo: [],
      // 图片地址
      nowimageurl: "",
      resultLoading: true,
      resultData: [],
      // 所有巡查人列表
      allStaffList: [],
      // 所有巡查路线列表
      allLineList: [],
      // search值
      // 时间间隔
      rangeTime: "",
      // 巡查路线ID
      routeId: "",
      pointName: "",
      // 巡查人ID
      staffId: "",
      staffName: "",
      staffData: [],
      dataTimeStart: "",
      inspectionTaskName: "",
      dataTimeEnd: "",
      // 图片
      imageUrlList: [],
      startTime: "",
      endTime: "",
      patrolLine: [],
      HistoryPatrolPondRecordList: [],
      imageDataList: [],
      pictureIdList: [],
      showPictureDialog: false,
      staffList: [],

    };
  },
  watch: {},
  created () {
    this.queryDataList();
  },
  mounted () {
    // 获取表格数据
    this.search();
    this.queryPatrolBase();
    this.queryHistoryPatrolPondRecord()
  },
  methods: {
    getTableDataList () {
      this.tableData = [];
      this.loading = true;
      let params = {
        page: this.currentPage,
        size: this.pageSize,
        entity: {
          staffName: this.staffName,
          startTime: this.startTime && this.startTime + ' 00:00:00',
          endTime: this.endTime && this.endTime + ' 24:00:00'
        }
      };
      this.searchObj=params.entity
      inspectionElectronicPatrolApi.queryPageByCondition(params).then(res => {
        this.loading = false;
        let data = res.data;
        // 赋值总条数
        if (data) {
          this.totalSize = data.totalElements;
          // 赋值数组
          this.tableData = data.content;
          this.addblankmet();
          this.resetActionBar();
        }
      });
    },
    // 巡查人
    async queryDataList () {
      const { data: staff } = await staffApi.queryByCondition({});
      if (staff !== undefined) {
        this.staffData = staff;
      } else this.staffData = [];
      const { data: resp } = await patrolInfoApi.queryByCondition();
      this.patrolLine = resp;
    },



    async queryHistoryPatrolPondRecord () {
      const res = await staffApi.queryByCondition({});
      this.staffList = res.data
    },
    // 巡检基地名称

    async queryPatrolBase () {
      const res = await PatrolPointManageApi.queryByCondition({});
      this.PatrolBaseList = res.data
    },

    // 时间转换
    dateFormat (row, colnum) {
      if (row.startTime) {
        return this.$moment(row[colnum.property]).format("YYYY-MM-DD HH:mm:ss");
      }
      if (row.endTime) {
        return this.$moment(row[colnum.property]).format("YYYY-MM-DD HH:mm:ss");
      }
    },
    // 搜索框时间
    startVal (e) {
      this.startTime = e;
    },
    endVal (e) {
      this.endTime = e;
    },
    searchs () {
      // let time1 = this.$moment(this.rangeTime[0]).format("YYYY-MM-DD HH:mm:ss");
      this.currentPage = 1;
    },
    handleEdit (row) {
      // console.log(row);
      // TODO 点击行元素后 edit
      this.formData = JSON.parse(JSON.stringify(row));
      // this.$refs.formData.resetFields();
      // console.log(this.formData)
    },

    handleSelectionChange (list) {
      this.taskIdList = [];
      this.taskIdList = list.map(item => item.taskId);
      if (this.taskIdList.length > 0) this.delActive = true;
      else this.delActive = false;
    },
    // 查看图片
    showResultmessage (Id) {
      let params = {
        pictureIdList: Id
      };
      HistoryPatrolPondRecordApi.queryByConditionList(params).then(async res => {
        this.imageUrlList = [{ pictureData: await blobToBase64(res) }];
        if (this.imageUrlList.length > 0) this.isShowimage = true;
        else this.$message.warning("暂无图片");
      });
    },
    // 获取结果
    showResult (pictureIdList) {
      if (pictureIdList !== undefined) {
        this.pictureIdList = pictureIdList
        pictureIdList.forEach(async item => {
          await HistoryPatrolPondRecordApi.fileDownload({ fileId: item }).then(res => {
            console.log(res.data);
            blobToBase64(res.data).then(res2 => {
              this.imageDataList.push(res2)
            })
          })
        })
        this.showPictureDialog = true;
      } else this.pictureIdList = []
    },
    closePictureDialog () {
      this.showPictureDialog = false
      this.imageDataList = []
    },
  }
};
</script>

<style scoped lang="scss">
@import "~@/styles/variables.scss";

.empty-content {
  height: 100px;
  display: flex;
  font-size: 20px;
  justify-content: center;
  align-items: center;
}

.common-layout {
  border: 1px solid $borderColor;
  height: calc(100% - #{$actionBarHeight + 10});
  padding: 10px;

  .search-box {
    display: flex;
    align-items: center;

    .label-input {
      display: flex;
      align-items: center;

      .label {
        min-width: 80px !important;
        white-space: nowrap;
      }

      // .label-80 {
      //   // width: 80px;
      // }
    }

    .search {
      display: flex;
      align-items: center;

      img {
        height: 30px;
      }
    }
  }

  .content {
    height: calc(100% - 50px);
    margin: 20px 0;

    .table-box {
      position: relative;
      height: 100%;
      overflow-y: auto;

      .el-table {
        width: 100%;
      }
    }
  }
}

// }
::v-deep .el-dialog {
  overflow-y: auto;

  // background-color: rgba($color: #82ceee, $alpha: 0.8);
  .el-form {
    display: flex;

    .el-form-item {
      display: flex;
    }
  }

  .searchbox {
    display: flex;
    align-items: center;
    margin-bottom: 10px;

    .label-input {
      color: cornsilk;
      display: flex;
      align-items: center;

      .label {
        margin-right: 2px;
      }
    }
  }

  .el-table__empty-text {
    color: #000 !important;
  }

  .el-dialog__body {
    text-align: initial;
    padding: 20px 10px 10px !important;
  }
}

::v-deep .el-dialog {
  border: 1px solid #000;
  border-radius: 10px;

  .el-dialog__header {
    border-radius: 9px 9px 0 0;

    .el-dialog__title {
      color: #fff;
    }
  }

  .el-dialog__body {
    padding: 5px 20px;
    font-size: 12px !important;

    .el-input {
      input {
        font-size: 12px;
      }
    }
  }

  .el-table {
    max-height: 200px;
    overflow-y: auto;
    background-color: rgba(255, 255, 255, 1);

    .cell {
      color: #000;
    }

    th {
      background-color: rgba(230, 230, 230, 1);
    }

    th.is-leaf {
      border-color: rgba(77, 77, 77, 1);
    }

    td {
      border-color: rgba(77, 77, 77, 1);
    }

    tr:hover {
      background-color: rgba(77, 77, 77, 1);
    }

    .el-table__empty-text {
      color: #000;
    }

    .current-row {
      // background-color: rgb(177, 177, 177);
      background-color: #dbdbdb !important;
    }

    .el-table__row--striped {
      background-color: rgba(255, 255, 255, 1);
    }

    // color: #000;
  }

  .el-table--border {
    border-color: rgba(77, 77, 77, 1);
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
  }

  .el-table--enable-row-hover .el-table__body tr:hover>td {
    background-color: rgb(177, 177, 177);
  }

  .el-table__body tr.current-row>td {
    background-color: #dbdbdb !important;
  }

  .el-form-item {
    margin-bottom: 10px;
  }

  .total-price {
    color: #000;
  }

  .el-table__body {
    // height: ;
    height: 0;
    // background-color: #003947;
  }
}

::v-deep .dialogIMG {
  .el-dialog {
    height: 80%;

    .el-dialog__header {
      padding: 30px;
    }

    .el-dialog__body {
      height: 92%;
      overflow-y: auto !important;
    }
  }
}
</style>
